package service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import model.EstpInfo;
import model.Knowledge;
import model.TeamInfo;
import model.User;

import dao.TeamInfoDao;

import service.TeamInfoManager;

public class TeamInfoManagerImpl implements TeamInfoManager {
	private TeamInfoDao teamInfoDao;
	public TeamInfoDao getTeamInfoDao() {
		return teamInfoDao;
	}
	public void setTeamInfoDao(TeamInfoDao teamInfoDao) {
		this.teamInfoDao = teamInfoDao;
	}
	public int addTeamInfoManager(String teamPersonName, int teamPersonSex,
			Date teamPersonBirthday, int teamPersonEdu, int teamPersonStep,
			int teamPersonjob) throws Exception {
			try {
				TeamInfo ti = new TeamInfo();
				ti.setTeamPersonName(teamPersonName);
				ti.setTeamPersonSex(teamPersonSex);
				ti.setTeamPersonBirthday(teamPersonBirthday);
				ti.setTeamPersonEdu(teamPersonEdu);
				ti.setTeamPersonStep(teamPersonStep);
				ti.setTeamPersonjob(teamPersonjob);
				Map session = ActionContext.getContext().getSession();
				User user = (User)session.get("USER");
				ti.setUser(user);
				teamInfoDao.save(ti);
				return ti.getId();
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
				throw new Exception("新增创业者信息时出现异常");
			}
	}
	
//	public int addOrUpdateTeamInfoManager(String teamPersonName, int teamPersonSex,
//			Date teamPersonBirthday, int teamPersonEdu, int teamPersonStep,
//			int teamPersonjob) throws Exception {
//			try {
//				Map session = ActionContext.getContext().getSession();
//				TeamInfo ti = (TeamInfo)session.get("T");
//				if(ti == null){
//					ti = new TeamInfo();
//				}
//				ti.setTeamPersonName(teamPersonName);
//				ti.setTeamPersonSex(teamPersonSex);
//				ti.setTeamPersonBirthday(teamPersonBirthday);
//				ti.setTeamPersonEdu(teamPersonEdu);
//				ti.setTeamPersonStep(teamPersonStep);
//				ti.setTeamPersonjob(teamPersonjob);
//				User user = (User)session.get("USER");
//				ti.setUser(user);
//				teamInfoDao.saveOrUpdate(ti);
//				return ti.getId();
//			} catch (Exception e) {
//				// TODO: handle exception
//				e.printStackTrace();
//				throw new Exception("新增或更新创业者信息时出现异常");
//			}
//	}

	public List<TeamInfo> getTeamInfoByUser(User user) throws Exception{
		try {
			List<TeamInfo> tInfo = teamInfoDao.getTeamInfoByUser(user);
			return tInfo;
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("按用户查找创业团队信息时出现异常");
		}
	}
	public void delAllInfo() throws Exception{
		try {
			Map session = ActionContext.getContext().getSession();
			User user = (User)session.get("USER");
			teamInfoDao.delete(user);
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			throw new Exception("删除创业团队信息时出现异常");
		}
	}
}
